package com.cs.springmvc.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractWizardFormController;

import com.cs.springmvc.model.UserModel;

/**
 * @author Sam.Lee
 * @version Created：Feb 5, 2013 2:04:29 PM
 */
public class InfoFillWizardFormController extends AbstractWizardFormController {

	public InfoFillWizardFormController() {
		setCommandClass(UserModel.class);
		setCommandName("user");
	}

	protected Map referenceData(HttpServletRequest request, int page)
			throws Exception {
		Map map = new HashMap();
		if (page == 1) { // 如果是填写学校信息页 需要学校类型信息
			map.put("schoolTypeList", Arrays.asList("高中", "中专", "大学"));
		}
		if (page == 2) {// 如果是填写工作信息页 需要工作城市信息
			map.put("cityList", Arrays.asList("济南", "北京", "上海"));
		}
		return map;
	}

	protected void validatePage(Object command, Errors errors, int page) {
		// TODO Auto-generated method stub
		super.validatePage(command, errors, page);
	}

	protected void postProcessPage(HttpServletRequest request, Object command,
			Errors errors, int page) throws Exception {
		// TODO Auto-generated method stub
		super.postProcessPage(request, command, errors, page);
	}

	protected ModelAndView processFinish(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		// 成功后的处理方法
		System.out.println(command);
		return new ModelAndView("redirect:/success");
	}

	protected ModelAndView processCancel(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		// 取消后的处理方法
		System.out.println(command);
		return new ModelAndView("redirect:/cancel");
	}

}
